//
//  ZJProjectInfoCell.m
//  这家测试项目
//
//  Created by IOS_DEVELOPER on 2017/6/29.
//  Copyright © 2017年 陈志凌. All rights reserved.
//

#import "ZJProjectInfoCell.h"

@implementation ZJProjectInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.JTVIEW.sd_layout.leftSpaceToView(self.contentView, 8).topSpaceToView(self.xiaoshouView, 8).rightSpaceToView(self.contentView, 8).autoHeightRatio(0);
    self.jiaotongPeitao.sd_layout.leftSpaceToView(self.JTVIEW, 18).topSpaceToView(self.JTVIEW, 8).widthIs(89).heightIs(21);
    self.jiaotongLine.sd_layout.leftSpaceToView(self.JTVIEW, 8).topSpaceToView(self.jiaotongPeitao, 8).rightSpaceToView(self.JTVIEW, 8).heightIs(1);
    self.traffic.sd_layout.leftSpaceToView(self.JTVIEW, 8).topSpaceToView(self.jiaotongLine, 8).rightSpaceToView(self.JTVIEW, 8).autoHeightRatio(0);

    
    self.JYVIEW.sd_layout.leftSpaceToView(self.contentView, 8).topSpaceToView(self.JTVIEW, 8).rightSpaceToView(self.contentView, 8).autoHeightRatio(0);
    self.line1.sd_layout.leftSpaceToView(self.JYVIEW, 9).topSpaceToView(self.JYVIEW, 8).widthIs(2).heightIs(21);
    self.jiaoyuPeitao.sd_layout.leftSpaceToView(self.JYVIEW, 18).topSpaceToView(self.JYVIEW, 8).widthIs(89).heightIs(21);
    self.jiaoyuLine.sd_layout.leftSpaceToView(self.JYVIEW, 8).topSpaceToView(self.jiaoyuPeitao, 8).rightSpaceToView(self.JYVIEW, 8).heightIs(1);
    self.education.sd_layout.leftSpaceToView(self.JYVIEW, 8).topSpaceToView(self.jiaoyuLine, 8).rightSpaceToView(self.JYVIEW, 8).autoHeightRatio(0);
    
    
    self.YLVIEW.sd_layout.leftSpaceToView(self.contentView, 8).topSpaceToView(self.JYVIEW, 8).rightSpaceToView(self.contentView, 8).autoHeightRatio(0);
    self.line2.sd_layout.leftSpaceToView(self.YLVIEW, 9).topSpaceToView(self.YLVIEW, 8).widthIs(2).heightIs(21);
    self.yiliaoPeitao.sd_layout.leftSpaceToView(self.YLVIEW, 18).topSpaceToView(self.YLVIEW, 8).widthIs(89).heightIs(21);
    self.yiliaoLine.sd_layout.leftSpaceToView(self.YLVIEW, 8).topSpaceToView(self.yiliaoPeitao, 8).rightSpaceToView(self.YLVIEW, 8).heightIs(1);
    self.medical.sd_layout.leftSpaceToView(self.YLVIEW, 8).topSpaceToView(self.yiliaoLine, 8).rightSpaceToView(self.YLVIEW, 8).autoHeightRatio(0);
    
    
    self.SYVIEW.sd_layout.leftSpaceToView(self.contentView, 8).topSpaceToView(self.YLVIEW, 8).rightSpaceToView(self.contentView, 8).autoHeightRatio(0);
    self.line3.sd_layout.leftSpaceToView(self.SYVIEW, 9).topSpaceToView(self.SYVIEW, 8).widthIs(2).heightIs(21);
    self.shangyePeitao.sd_layout.leftSpaceToView(self.SYVIEW, 18).topSpaceToView(self.SYVIEW, 8).widthIs(89).heightIs(21);
    self.shangyeLine.sd_layout.leftSpaceToView(self.SYVIEW, 8).topSpaceToView(self.shangyePeitao, 8).rightSpaceToView(self.SYVIEW, 8).heightIs(1);
    self.business.sd_layout.leftSpaceToView(self.SYVIEW, 8).topSpaceToView(self.shangyeLine, 8).rightSpaceToView(self.SYVIEW, 8).autoHeightRatio(0);

    self.headView.sd_layout.leftSpaceToView(self.contentView, 8).topSpaceToView(self.headImg, 8).rightSpaceToView(self.contentView, 8).autoHeightRatio(0);
    self.headImg.sd_layout.leftSpaceToView(self.contentView, 0).topSpaceToView(self.contentView, 0).rightSpaceToView(self.contentView, 0).heightIs(207);
    self.topLine.sd_layout.leftSpaceToView(self.headView, 0).topSpaceToView(self.loupanjianjie, 8).rightSpaceToView(self.headView, 0).heightIs(1);
    self.total_description.sd_layout.leftSpaceToView(self.headView, 12).topSpaceToView(self.topLine, 8).rightSpaceToView(self.headView, 12).autoHeightRatio(0);
    
    self.loupanView.sd_layout.leftSpaceToView(self.contentView, 8).topSpaceToView(self.headView, 8).rightSpaceToView(self.contentView, 8).heightIs(285);
    self.xiaoshouView.sd_layout.leftSpaceToView(self.contentView, 8).topSpaceToView(self.loupanView, 8).rightSpaceToView(self.contentView, 8).heightIs(340);
    self.guihuaView.sd_layout.leftSpaceToView(self.contentView, 8).topSpaceToView(self.SYVIEW, 8).rightSpaceToView(self.contentView, 8).heightIs(321);
    
    [self shadowView:self.loupanView];
    [self shadowView:self.xiaoshouView];
    [self shadowView:self.guihuaView];
    [self shadowView:self.headView];
    [self shadowView:self.JTVIEW];
    [self shadowView:self.JYVIEW];
    [self shadowView:self.YLVIEW];
    [self shadowView:self.SYVIEW];
    
     self.loupanLine.sd_layout.leftSpaceToView(self.loupanView, 8).topSpaceToView(self.loupan, 8).rightSpaceToView(self.loupanView, 8).heightIs(1);
    self.xiaoshouLine.sd_layout.leftSpaceToView(self.xiaoshouView, 8).topSpaceToView(self.xiaoshou, 8).rightSpaceToView(self.xiaoshouView, 8).heightIs(1);
    self.xiaoquLine.sd_layout.leftSpaceToView(self.guihuaView, 8).topSpaceToView(self.xiaoqu, 8).rightSpaceToView(self.guihuaView, 8).heightIs(1);
    
    self.developer.sd_layout.leftSpaceToView(self.loupanView, 76).topSpaceToView(self.loupanLine, 8).rightSpaceToView(self.loupanView, 8).autoHeightRatio(0);
#warning 项目改动
    self.price_total.textColor = [UIColor blackColor];
    
    if ([allConstProjectid integerValue] != 7) {
        self.average_price.textColor = [Utils colorWithHexString:@"ffb400"];
        self.price_total.textColor = [Utils colorWithHexString:@"ffb400"];
    }
    
    self.weizhiImg.sd_layout.topEqualToView(self.topAddress).leftSpaceToView(self.topAddress,SCREEN_WIDTH - self.topAddress.width - 30).heightIs(15).widthIs(15);
    
}

-(void)setModel:(ZJProjectDetailModel *)model{
    _model = model;
    
    self.headImg.image = [UIImage imageWithContentsOfFile:[Utils imgPath:@"lpzs_pic_bg@3x.png"]];
    self.weizhiImg.image = [UIImage imageWithContentsOfFile:[Utils imgPath:@"weizi_icon@3x.png"]];
    
    self.developer.text = model.developer?:@"暂无数据";
    self.building_type.text = model.building_type?:@"暂无数据";
    self.tags.text = model.tags?:@"暂无数据";
    self.address.text = model.address?:@"暂无数据";
    self.price_total.text = model.price_total?:@"暂无数据";
    self.property_year.text = model.property_year?:@"暂无数据";
    self.renovation.text = model.renovation?:@"暂无数据";
    self.sale_status.text = model.sale_status?:@"暂无数据";
    self.open_date.text = model.open_date?:@"暂无数据";
    self.sale_address.text = model.sale_address?:@"暂无数据";
    self.sale_phone.text = model.sale_phone?:@"暂无数据";
    self.handed_date.text = model.handed_date?:@"暂无数据";
    self.traffic.text = model.traffic?:@"暂无数据";
    self.education.text = model.education?:@"暂无数据";
    self.medical.text = model.medical?:@"暂无数据";
    self.business.text = model.business?:@"暂无数据";
    self.area_total.text = model.area_total?:@"暂无数据";
    self.area_building.text = model.area_building?:@"暂无数据";
    self.volume_ratio.text = model.volume_ratio?:@"暂无数据";
    self.parkings.text = model.parkings?:@"暂无数据";
    self.house_total.text = model.house_total?:@"暂无数据";
    self.green_ratio.text = model.green_ratio?:@"暂无数据";
    self.project_name.text = model.project_name?:@"暂无数据";
    self.average_price.text = model.average_price?:@"暂无数据";
    self.topAddress.text = model.address?:@"暂无数据";
    self.total_description.text = model.total_description?:@"暂无数据";
    self.building_total.text = model.building_total?:@"暂无数据";
    
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:8];
    UIColor *color1 = [Utils colorWithHexString:@"999999"];
    NSAttributedString *string = [[NSAttributedString alloc] initWithString:self.total_description.text attributes:@{NSForegroundColorAttributeName : color1, NSParagraphStyleAttributeName: paragraphStyle}];
    
    NSAttributedString *string1 = [[NSAttributedString alloc] initWithString:self.traffic.text attributes:@{NSForegroundColorAttributeName : color1, NSParagraphStyleAttributeName: paragraphStyle}];
    
    NSAttributedString *string2 = [[NSAttributedString alloc] initWithString:self.education.text attributes:@{NSForegroundColorAttributeName : color1, NSParagraphStyleAttributeName: paragraphStyle}];
    
    NSAttributedString *string3 = [[NSAttributedString alloc] initWithString:self.medical.text attributes:@{NSForegroundColorAttributeName : color1, NSParagraphStyleAttributeName: paragraphStyle}];
    
    NSAttributedString *string4 = [[NSAttributedString alloc] initWithString:self.business.text attributes:@{NSForegroundColorAttributeName : color1, NSParagraphStyleAttributeName: paragraphStyle}];
    
    self.total_description.attributedText = string;
    
    self.total_description.isAttributedContent = YES;
    
    self.traffic.attributedText = string1;
    
    self.traffic.isAttributedContent = YES;
    
    self.education.attributedText = string2;
    
    self.education.isAttributedContent = YES;
    
    self.medical.attributedText = string3;
    
    self.medical.isAttributedContent = YES;
    
    self.business.attributedText = string4;
    
    self.business.isAttributedContent = YES;
    
    float height = self.sale_phone.y + self.sale_phone.height;
    
    for (int i = 0; i < model.licence.count; i ++) {
        
        height = height + 23;
        NSDictionary * dict = model.licence[i];
        UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(94, height, self.xiaoshouView.width - 94, 16)];
        btn.titleLabel.font = [UIFont systemFontOfSize:13.0f];
        [btn setTitle:dict[@"licence_name"] forState:0];
        [btn addTarget:self action:@selector(clickLicence:) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitleColor:[Utils colorWithHexString:@"ffb400"] forState:0];
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [self.xiaoshouView addSubview:btn];
        
        [self.headView setupAutoHeightWithBottomView:btn bottomMargin:8];
    }
    self.xiaoshouView.sd_layout.leftSpaceToView(self.contentView, 8).topSpaceToView(self.loupanView, 8).rightSpaceToView(self.contentView, 8).heightIs(230 + model.licence.count * 20);
    [self.headView setupAutoHeightWithBottomView:self.total_description bottomMargin:18];
    [self.JTVIEW setupAutoHeightWithBottomView:self.traffic bottomMargin:8];
    [self.JYVIEW setupAutoHeightWithBottomView:self.education bottomMargin:8];
    [self.YLVIEW setupAutoHeightWithBottomView:self.medical bottomMargin:8];
    [self.SYVIEW setupAutoHeightWithBottomView:self.business bottomMargin:8];
    [self setupAutoHeightWithBottomView:self.guihuaView bottomMargin:8];
    
//    [self.peitaoView layoutSubviews];
    [self.contentView setNeedsLayout];
    [self.contentView layoutSubviews];
}

-(void)shadowView:(UIView *)view{

    view.layer.shadowColor = RGB(224, 224, 224).CGColor;;
    view.layer.shadowOpacity = 0.8f;
    view.layer.shadowOffset = CGSizeMake(0,0.1);
}
-(void)clickLicence:(UIButton *)btn{

    [[NSNotificationCenter defaultCenter]postNotificationName:@"clickLicence" object:@{@"name":btn.titleLabel.text}];
}
@end
